#ifndef _ALLOTER_H
#define _ALLOTER_H

#include <stdint.h>

struct _CHN_SLOT
{
    uint16_t rx;
    uint16_t tx;
    uint16_t data_cnt;
};


//1KB内存池  16块
#define MAX_BUFFER_SZ           (MAX_POOL_SZ-BUFFER_NO_SZ) 
#define BUFFER_NO_SZ            (MAX_POOL_SZ>>BLK_NO_SHIFT)
#define MAX_POOL_SZ             1024 

#define BLK_NO_SHIFT   6
#define BLK_SZ     (0x01 << BLK_NO_SHIFT)
#define INVALID_BLK_NO  0xFF

#define INVALID_PTR     (INVALID_BLK_NO << BLK_NO_SHIFT)   // 0001 1111 111    0 0000

struct _CHN_POOL_MGR//内存池
{ 
    uint8_t    buffer[MAX_POOL_SZ];  
    uint16_t   free_bitmap; //1：空闲   0：使用
};

void init_chn_pool_mgr(void);
uint8_t put_chn_bytes(struct _CHN_SLOT *pCHN_SLOT, unsigned char buffer[], uint8_t len);
uint8_t get_chn_bytes(struct _CHN_SLOT *pCHN_SLOT, unsigned char buffer[], uint8_t len);
uint8_t peek_chn_bytes(struct _CHN_SLOT *pCHN_SLOT, unsigned char data[], uint8_t len);
void empty_a_chn_slot(struct _CHN_SLOT *pCHN_SLOT,  uint16_t len);

#endif 

